home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / ov143b.zip / OV.C < prev    next >
C/C++ Source or Header  |  1993-01-04  |  16KB  |  411 lines

  1. /*  107  13-Jun-87  ov.c
  2.  
  3.                             O V E R V I E W
  4.  
  5.         This program allows the user to perform common operations on
  6.         disk files in a visual, tabular manner.
  7.  
  8.         Copyright (c) 1987 by Blue Sky Software.  All rights reserved.
  9. */
  10.  
  11. #define VERSION "OverView 1.43, 13-Jun-87"
  12.  
  13. #include <stdio.h>
  14. #include <setjmp.h>
  15. #include <dos.h>
  16. #include "ov.h"
  17. #include "menu.h"
  18. #include "direct.h"
  19. #include "strmem.h"
  20.  
  21. int brkhit;                            /* NZ when ^Break/^C hit */
  22. int winupdate;                         /* NZ when windows need updating */
  23. unsigned char anyshowall;              /* NZ when show all is active */
  24. unsigned char dir_display;             /* NZ when dir tree displayed */
  25. unsigned char def_display;             /* NZ when define screen displayed */
  26. unsigned char help_display;            /* NZ when help is active */
  27. unsigned char view_display;            /* NZ when viewing a file */
  28. unsigned char restricted;              /* NZ when some functions disabled */
  29.  
  30. char *initialdir;                      /* name of initial dir */
  31. unsigned int dataseg;                  /* ov's data segment reg value */
  32. jmp_buf back_to_main;                  /* error handling jmp_buf block */
  33. char version[] = VERSION;              /* current OverView version #, date */
  34.  
  35. char *cantopen = "Can't open ";                        /* common messages */
  36. char *none_tagged = "There are NO tagged files.";
  37.  
  38. FILE_ENT files[MAX_FILES];             /* array of file entries */
  39.  
  40. extern unsigned char _osmajor;         /* DOS major version # */
  41.  
  42. /* function declarations */
  43.  
  44. char *getcwd();
  45. void vfind(int);
  46. FILE_ENT *nxtfile();
  47. int sel_all(), define(), help(), show_all();
  48. int quit(), login(), erase_current(), erase_tagged(), view(), sortname();
  49. int copy_current(), copy_tagged(), info(), renew(), do_cmd(), spawn_cli();
  50. int dtree(), dir_login(), dir_mkdir(), dir_rmdir(), dir_exit(), sel_attrib();
  51. int ren_cur(), ren_tag(), set_mask(), clr_mask(), invert_mask(), sel_tagged();
  52. int sort_asc(), sort_desc(), sort_name(), sort_ext(), sort_date(), sort_size();
  53. int set_vol(), tag_current(), tag_name(), tag_date(), tag_reset(), tag_today();
  54. int tag_modified(), tag_invert(), attrib_current(), attrib_tagged(), execute();
  55. int win_open(), win_close(), win_expand(), win_next(), win_prev(), sort_none();
  56.  
  57. /* define the current window structure */
  58.  
  59. struct window cw = { NULL, NULL, 0, FIRST_NROW, NAME_ROWS, FIRST_NROW,
  60.    NAME_ROWS, 0, 0, 0, 0, 0, 0, 0, NULL, 0, 0, 0, 0, NULL, 'A', sortname, 0, 0,
  61.    RDONLY | HIDDEN | SYSTEM | DIR | ARCHIVE, 1 };
  62.  
  63. /* define some of the menus */
  64.  
  65. char tagged[] =  "Tagged";
  66. char current[] = "Current";
  67.  
  68. extern int menu_row, menu_hilite, menu_lolite;
  69. extern MENU *top_menu, top_file_menu[], top_dir_menu[];
  70.  
  71. MENU attrib_menu[] = {
  72.    { current,"Change current file's attributes", attrib_current, NULL },
  73.    { tagged, "Change attributes of all tagged files", attrib_tagged, NULL },
  74.    { NULL, NULL, NULL, NULL }
  75. };
  76.  
  77. MENU copy_menu[] = {
  78.    { current, "Copy current file", copy_current, NULL },
  79.    { tagged, "Copy the tagged files", copy_tagged, NULL },
  80.    { NULL, NULL, NULL, NULL }
  81. };
  82.  
  83. MENU erase_menu[] = {
  84.    { current, "Erase current file", erase_current, NULL },
  85.    { tagged, "Erase all tagged files", erase_tagged, NULL },
  86.    { NULL, NULL, NULL, NULL }
  87. };
  88.  
  89. MENU mask_menu[] = {
  90.    { "Set", "Set file mask", set_mask, NULL },
  91.    { "Clear", "Clear file mask", clr_mask, NULL },
  92.    { "Invert", "Invert the meaning of the mask", invert_mask, NULL },
  93.    { NULL, NULL, NULL, NULL }
  94. };
  95.  
  96. MENU ren_menu[] = {
  97.    { current, "Rename or move current file", ren_cur, NULL },
  98.    { tagged, "Move all tagged files", ren_tag, NULL },
  99.    { NULL, NULL, NULL, NULL }
  100. };
  101.  
  102. MENU select_menu[] = {
  103.    { "Attrib", "Set selection attributes", sel_attrib, NULL },
  104.    { "Mask", "Set, Clear, or Invert file name selection mask", NULL, mask_menu },
  105.    { "Reset", "Reset selection criteria to defaults", sel_all, NULL },
  106.    { "Showall", "Toggle selection of all files on current drive", show_all, NULL },
  107.    { tagged, "Select all tagged files", sel_tagged, NULL },
  108.    { NULL, NULL, NULL, NULL }
  109. };
  110.  
  111. MENU sort_submenu[] = {
  112.    { "Ascending", "Sort in ascending order", sort_asc, NULL },
  113.    { "Descending", "Sort in descending order", sort_desc, NULL },
  114.    { NULL, NULL, NULL, NULL }
  115. };
  116.  
  117. MENU sort_menu[] = {
  118.    { "Name", "Sort by primary name", sort_name, NULL },
  119.    { "Ext", "Sort by extension", sort_ext, NULL },
  120.    { "Date", "Sort by date", sort_date, NULL },
  121.    { "Size", "Sort by size", sort_size, NULL },
  122.    { "Options", "Set sort options", NULL, sort_submenu },
  123.    { "Unsorted", "Do not sort entries", sort_none, NULL },
  124.    { NULL, NULL, NULL, NULL }
  125. };
  126.  
  127. MENU tag_menu[] = {
  128.    { current, "Tag/Untag current file", tag_current, NULL },
  129.    { "Date", "Tag files by date and time", tag_date, NULL },
  130.    { "Invert", "Invert the tag state of all files", tag_invert, NULL },
  131.    { "Modified", "Tag files with Archive attribute", tag_modified, NULL },
  132.    { "Name", "Tag files by name", tag_name, NULL },
  133.    { "Reset", "Untag all files", tag_reset, NULL },
  134.    { "Today", "Tag files created/modified today", tag_today, NULL },
  135.    { NULL, NULL, NULL, NULL }
  136. };
  137.  
  138. MENU win_menu[] = {
  139.    { "Open", "Open additional window", win_open, NULL },
  140.    { "Close", "Close current window", win_close, NULL },
  141.    { "Expand", "Expand current window (closes others)", win_expand, NULL },
  142.    { "Next", "Switch to next window", win_next, NULL },
  143.    { "Prev", "Switch to previous window", win_prev, NULL },
  144.    { NULL, NULL, NULL, NULL }
  145. };
  146.  
  147. MENU other_menu[] = {
  148.    { "Attrib", "Change attributes of file(s)", NULL, attrib_menu },
  149.    { "Command", "Execute a DOS command", do_cmd, NULL },
  150.    { "Define", "Define (set) OverView parameters", define, NULL },
  151.    { "Interpreter", "Spawn a DOS command interpreter", spawn_cli, NULL },
  152.    { "Select", "Set file selection criteria", NULL, select_menu },
  153.    { "Volume", "Create or change volume label", set_vol, NULL },
  154.    { "Window", "Open, close, switch display windows", NULL, win_menu },
  155.    { "Xecute", "Execute file", execute, NULL },
  156.    { "Other", "Help, Copy, Dir, Erase, Info, Login, New, Rename, Sort, Tag, View, Quit", NULL, top_file_menu },
  157.    { NULL, NULL, NULL, NULL }
  158. };
  159.  
  160. MENU top_file_menu[] = {
  161.    { "Help", "Help on using OVERVIEW", help, NULL },
  162.    { "Copy", "Copy file(s)", NULL, copy_menu },
  163.    { "Dir", "Display the disk directory tree", dtree, top_dir_menu },
  164.    { "Erase", "Erase (delete) file(s)", NULL, erase_menu },
  165.    { "Info", "Toggle display of extra file information", info, NULL },
  166.    { "Login", "Login (switch) to another disk/directory", login, NULL },
  167.    { "New", "Reread and redisplay directory", renew, NULL },
  168.    { "Rename", "Rename or move file(s)", NULL, ren_menu },
  169.    { "Sort", "Sort files by Name, Extension, Date, or Size", NULL, sort_menu },
  170.    { "Tag", "Tag file(s)", NULL, tag_menu },
  171.    { "View", "View file", view, NULL },
  172.    { "Other", "Attrib, Command, Define, Interperter, Select, Volume, Window, Xecute", NULL, other_menu },
  173.    { "Quit", "Exit OverView and return to DOS", quit, NULL },
  174.    { NULL, NULL, NULL, NULL }
  175. };
  176.  
  177.  
  178.  
  179. /******************************************************************************
  180.  **                           M A I N                                        **
  181.  *****************************************************************************/
  182.  
  183. main(argc,argv)
  184. int argc;
  185. char *argv[];
  186. {
  187.    setvattrib(DIS_NORM);       /* select initial video attribute */
  188.  
  189.    /* display the signon while initializing */
  190.  
  191.    init_tty();                         /* init the terminal settings */
  192.    def_read();                         /* read configuration file    */
  193.    ovlogo();                           /* display the logo screen    */
  194.  
  195.    /* init internal data structures and display a screen of files */
  196.  
  197.    {  struct SREGS sr;                 /* get OverView's data seg reg value */
  198.       segread(&sr);                    /*   for a couple of other routines  */
  199.       dataseg = sr.ds;                 /*   to use */
  200.    }
  201.  
  202.    getcwd(cw.dirbuf,MAX_PATHLEN);      /* get current directory pathname */
  203.    initdrive(*cw.dirbuf);              /* init DRIVE_ENT 4 current drive */
  204.    initialdir = Strdup(cw.dirbuf);     /* save the initial dir spec */
  205.  
  206.    getfiles();                         /* get files from current directory */
  207.    adjust_window();                    /* set # rows, cols, etc */
  208.  
  209.    getchr();                           /* any keypress to continue */
  210.  
  211.    menu_row = MENU_ROW;                /* initialize menu subsystem */
  212.    menu_hilite = DIS_HIGH;
  213.    menu_lolite = DIS_NORM;
  214.    top_menu = top_file_menu;
  215.  
  216.    setup_file_scr();                   /* display the static screen image */
  217.    update_header();                    /* display header info */
  218.    update_window(1);                   /*   and a window of data */
  219.  
  220.    grabbrk(&brkhit);           /* grab the ^Break/^C interrupt handler */
  221.  
  222.    /* call setjmp to establish the error handling jmp_buf,  errors in
  223.       subfuntions will return here to start the next command */
  224.  
  225.    setjmp(back_to_main);
  226.  
  227.    /* main processing, obey each user command, terminate when done or
  228.       user enters the EOF character or hits ^Break/^C */
  229.  
  230.    while (1) {
  231.       obey();             /* only returns after ^Z or ^Break/^C */
  232.       quit();             /* doesn't return if quitting */
  233.    }
  234.  
  235. }
  236.  
  237.  
  238. /******************************************************************************
  239.  **                           O B E Y                                        **
  240.  *****************************************************************************/
  241.  
  242. obey() {               /* obey / process a user command */
  243.  
  244.    register int ch, i;
  245.    char *dp, *dirplus();
  246.  
  247.    menu_init();                /* display the initial menu */
  248.  
  249.    while ((ch = getchr()) != EOF_CH) { /* get a char from the user */
  250.  
  251.       brkhit = 0;              /* clr brk flag before each ov command */
  252.  
  253.       switch (ch) {
  254.  
  255.          case LEFT: case RIGHT:        /* left, right arrows */
  256.          case UP:   case DOWN:         /* up, down arrows */
  257.          case HOME: case END:
  258.          case PGDN: case PGUP:
  259.  
  260.             if (dir_display)
  261.                dir_move(ch);           /* move the dir pointer */
  262.             else if (view_display)
  263.                view_move(ch);          /* move within the view buffer/file */
  264.             else if (def_display)
  265.                def_move(ch);           /* move within define screen mode */
  266.             else if (!restricted)
  267.                move_file(ch);          /* move the file pointer */
  268.  
  269.             break;
  270.  
  271.  
  272.          case ' ': case 9:             /* advance the menu selection pointer */
  273.             menu_advance();
  274.             break;
  275.  
  276.  
  277.          case 8:                       /* backup the menu selection pointer */
  278.             menu_backup();
  279.             break;
  280.  
  281.  
  282.          case RETURN:                  /* CR - do current menu selection */
  283.             menu_do_current();
  284.             break;
  285.  
  286.  
  287.          case 27:                      /* escape - return to top menu */
  288.             menu_init();               /* reset the menu subsystem */
  289.             break;
  290.  
  291.  
  292.          case TAG:                     /* single key command to tag current */
  293.             if (!restricted && !def_display) {
  294.                tag_current();
  295.                if (cw.curidx < cw.nfiles-1)
  296.                   move_file(DOWN);
  297.             }
  298.             break;
  299.  
  300.  
  301.          case GOPAR:                   /* login to the parent dir */
  302.             if (dir_display)
  303.                dir_move(GOPAR);
  304.             else
  305.                if (!restricted) {
  306.                   switch_dir(dp = dirplus(&files[cw.curidx],".."));
  307.                   free(dp);
  308.                   menu_init();
  309.                }
  310.             break;
  311.  
  312.          case GOSUB:                   /* login to dir under file ptr */
  313.             if (dir_display) {
  314.                dir_login();
  315.                menu_init();
  316.             } else {
  317.                if (!restricted)
  318.                   if (files[cw.curidx].flags & DIR) {
  319.                      switch_dir(dp = dirplus(&files[cw.curidx],
  320.                                              files[cw.curidx].name));
  321.                      free(dp);
  322.                      menu_init();
  323.                   } else
  324.                      tone(100,5);      /* beep the users mistake */
  325.             }
  326.             break;
  327.  
  328.          case NEXTT:                   /* goto next tagged file/find string */
  329.          case PREVT:                   /* goto prev tagged file/find string */
  330.             if (view_display)
  331.                vfind(ch == NEXTT);
  332.             else if (!restricted)
  333.                tag_find(ch == NEXTT ? 1 : -1);
  334.             break;
  335.  
  336.          case OPENW:                   /* open another file display window */
  337.             if (!restricted)
  338.                win_open();
  339.             break;
  340.  
  341.          case CLOSEW:                  /* close current file display window */
  342.             if (!restricted)
  343.                win_close();
  344.             break;
  345.  
  346.          case NEXTW:                   /* goto next file display window */
  347.             if (!restricted)
  348.                win_next();
  349.             break;
  350.  
  351.          case PREVW:                   /* goto prev file display window */
  352.             if (!restricted)
  353.                win_prev();
  354.             break;
  355.  
  356.          default:                      /* see if menu choice or UDK */
  357.  
  358.             if (ch >= UDK_START && ch <= UDK_END) {    /* UDK? */
  359.                if (!restricted && !def_display) {
  360.                   do_udk(ch);
  361.                   menu_init();
  362.                }
  363.                break;
  364.             }
  365.  
  366.             /* is it a menu selection? */
  367.  
  368.             if (!menu_do_char(ch))     /* do menu selection starting with ch */
  369.                tone(100,5);            /* beep if not a valid selection */
  370.             break;
  371.  
  372.       }
  373.  
  374.       if (winupdate) {                 /* some commands ask for one or */
  375.          refresh_screen(1);            /* more windows to be updated */
  376.          update_header();              /* make sure header is current */
  377.          winupdate = 0;
  378.       }
  379.    }
  380. }
  381.  
  382.  
  383. /******************************************************************************
  384.  **                             Q U I T                                      **
  385.  *****************************************************************************/
  386.  
  387. quit() {               /* exit from overview */
  388.  
  389.    int ch;
  390.  
  391.    /* Ask the user if he really wants to exit (default = N).  If so, check
  392.       to see if we are still in the initial startup dir.  If so, just exit.
  393.       If not, ask if we should return to the original dir before
  394.       quitting (default = return). */
  395.  
  396.    ch = ask("Quit OVERVIEW and return to DOS? (y/N): ");
  397.  
  398.    if (yes(ch)) {
  399.  
  400.       getcwd(cw.dirbuf,MAX_PATHLEN);   /* can mess cw.dibuf up cause quitting */
  401.  
  402.       if (strcmp(initialdir,cw.dirbuf) != 0) {
  403.          ch = ask("Exit to current directory, or Return to original? (e/R): ");
  404.          if (toupper(ch) != 'E')
  405.             change_dir(initialdir);
  406.       }
  407.       reset_tty();                     /* restore pre OV tty settings */
  408.       exit();                          /* So long, thanks for all the fish */
  409.    }
  410. }
  411.